<template>
	<view class="content">
		
		<view class="myService">
			<uni-nav-bar left-icon="back" title="物流批次" @clickLeft="gotoBack" :border="false" color="#fff" rightIcon="headphones" right-text="客服"  backgroundColor="transparent"></uni-nav-bar>
			<view class="service">
				<view class="topV">
					<view class="service-title">{{msgDict.orderInfo}}</view>
					<view class="status">{{statusName}}</view>
				</view>
				<view class="service-menu">
					<view class="item">
						<view class="labCode">{{msgDict.orderCode}}</view>
						<view class="labTime">{{orderCode}}</view>
					</view>
					<view class="item">
						<view class="labCode">{{msgDict.createTime}}</view>
						<view class="labTime">
							<uni-dateformat :date="createTime"></uni-dateformat>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="itemG" v-for="(item,index2) in list" :key="index2">
			
			<view class="topView">
				<view class="Itemtime">
					<uni-dateformat :date="item.deliveryTime"></uni-dateformat>
				</view>
				<view class="ItemNum" @click="btntoDetailClick(item.deliveryCode)">
					<view class="labKey">
						{{msgDict.delivery}}:
					</view>
					<view class="labVolue">
						{{item.deliveryCode}}
					</view>
					<uni-icons type="arrowright" size="25" color="#666"></uni-icons>
				</view>
				<view class="itemType">{{item.lastNodeName | showLastNodeName }}</view>
			</view>
			<view class="bottomView">
				<view class="btnCheck btnRed" @click="btnLogisticsClick(item.deliveryCode,item.izFinished)">
					{{msgDict.details}}
				</view>
				
				<view class="btnCheck" v-if="item.izFinished == 0"  @click="btnReceivClick(item.deliveryCode,index2)">
					{{msgDict.confirmReceipt}}
				</view>
				<view class="btnCheck" v-if="item.izFinished == 1" @click="btnEvaClick(item.deliveryCode,index2)">
					{{msgDict.evaluate}}
				</view>
				
			</view>
		</view>
	</view>
</template>
<script>
	import {deliveryBatch,ensureOrder} from '../../api/index.js'
	export default {
		data() {
			return {
				list:[],
				userId:undefined,
				orderCode:'',
				createTime:'',
				isRefresh:false,
				msgDict:{},
				statusName:''
			}
		},
		onLoad(options) {
		   this.msgDict = getApp().globalData.$t('logisticsGoods');
		   this.userId = getApp().globalData.userId;
			if (options.orderCode) {
			    this.statusName = options.statusName
				this.orderCode = options.orderCode
				this.requstOrderInfo({orderCode:options.orderCode,type:'1'});
			
			}
		},
		onShow() {
			if(this.isRefresh){
			   this.isRefresh=false;
			   this.requstOrderInfo({ orderCode:this.orderCode,type:'1'});
			}
		},
		onPullDownRefresh() {
		
		   this.requstOrderInfo({ orderCode:this.orderCode,type:'1'});
			
		},
	 
		methods: {
			
			async requstOrderInfo(dict){
				try{
					let {result} = await deliveryBatch(dict);
					this.list = result;
				     
					if(result.length > 0){
						
						this.createTime = result[0].orderCreateTime
					}
					uni.stopPullDownRefresh()
				}catch{
					uni.stopPullDownRefresh()
				}
			},
			async requstEnsureOrder(dict,index){
				
				
				let res = await ensureOrder(dict);
			     
				 uni.showToast({
				 	title:'收货成功',
				 	icon:'none'
				 })
				 let item = this.list[index];
				 item.izFinished = 1;
				 this.list.splice(index,1,item);
				 
				   
			
			},
			btntoDetailClick(e){
				uni.navigateTo({
					url:'../LogisticsDetail/LogisticsDetail?orderCode='+e
				})
			},
			btnLogisticsClick(e,izFinished){
				
				let showType  =''
				if (izFinished == 1) {
					showType = '已收货'
				} else{
					showType = '待收货'
				}
				
				uni.navigateTo({
					url:'../LogisticsGoods/LogisticsGoods?deliveryCode='+ e + '&orderCode='+this.orderCode+'&izFinished='+showType
				})
			},
			btnEvaClick(deliveryCode,index){
				
				uni.navigateTo({
					url:'../appraise/appraise?deliveryCode='+ deliveryCode+'&orderCode='+this.orderCode
				})
				
			},
			btnReceivClick(e,index){
				uni.showModal({
					title:'注意',
					content:'是否确认收货',
					success:(res)=> {
						if (res.confirm) {
							
							this.requstEnsureOrder({userId:this.userId,orderCode:this.orderCode,deliveryCode:e},index)
						}
					}
				})
			},
			gotoBack(){
				uni.navigateBack({
					delta:1
				})
			}
		},
		filters:{
			showType(val){
				
				if (val == '0') {
					return '待收货'
				} else{
					return '已收货'
				}
				
			},
			showLastNodeName(val){
				if (val) {
					return val
				} else {
					return '未发货'
				}
			}
		}
	}
</script>

<style lang="less">
page{
	height: 100%;
	background-color: #f2f2f2;
}
 .content{
	 // padding: 0rpx 20rpx;
 }
	 
 .myService{
 	// padding: 20rpx 0rpx 0;
    // margin-bottom: 20rpx;
	padding-top:  var(--status-bar-height);
	background: linear-gradient(180deg, #8250FD 0%, #5644E5 100%);
	height: 380rpx;
	margin-bottom: 60rpx;
	
 	.service{
 		background-color: #fff;
 		border-radius: 20rpx;
 		// padding-bottom: 10rpx;
 		margin: 64rpx 20rpx 0;
 		
 		.topV{
 			height: 88rpx;
 			display: flex;
 			justify-content: space-between;
 			align-items: center;
 			padding: 0 20rpx;
 			border-bottom: thin solid #f2f2f2;
 			.service-title{
 				
 				font-size: 28rpx;
 				font-weight: 500;
 				color: #333333;
 				// border-left: 10rpx solid #FFA500;
 				padding-left: 10rpx;
 				// height:52rpx;
 			}
 			.status{
 				
 				font-size: 26rpx;
 				font-weight: 400;
 				color: #6EB74B;
 				
 			}
 			
 		}
 		.service-menu{
 			
 			padding: 0 20rpx;
 			
 			font-size: 34rpx;
 			font-weight: 400;
 			color: #333;
 			
 		}
 		.item{
 			display: flex;
 			flex-direction: row;
 			align-items: center;
 			height: 85rpx;
 			border-top: thin solid #f2f2f2;
 			.labCode{
 				font-size: 26rpx;
 				color: #999;
 			}
			.labTime{
				font-size: 26rpx;
				color: #333;
				padding-left: 20rpx;
			}
 		}
 	}
 }
  .itemG{
	 background-color: #fff;
	 border-radius: 20rpx;
	 margin:  0 20rpx 20rpx; 
	 .topView{
	 	 margin: 0 20rpx;
	 	  // margin: 20rpx;
	 	  // display: flex;
	 	  // justify-content: space-between;
	 	  
	 	  .Itemtime{
	 	  	  // text-align: center;
	 	  	  font-size: 28rpx;
	 	  	  color: #999;
	 	  		  height: 88rpx;
	 	  		  line-height: 88rpx;
	 	  	  // padding-top: 28rpx;
	 	  }
	 
	 }
  }
  .ItemNum{
	  
	  display: flex;
	  align-items: center;
	  height: 85rpx;
	  border-bottom: thin solid #f2f2f2;
	  border-top: thin solid #f2f2f2;
	  
	 
	  .labKey{
		  color: #999;
		  font-size: 26rpx;
		  // width: 140rpx;
	  }
	  .labVolue{
		  flex: 1;
		  color: #333;
		  font-size: 26rpx;
		  font-weight: 400;
		  padding-left: 20rpx;
	  }
  }
  .itemType{
	  color: #999;
	  font-size: 26rpx;
	  margin-top: 30rpx;

  }
  
  .bottomView{
	  
	  height: 80rpx;
	  margin-top: 30rpx;
	  display: flex;
	  // justify-content: space-between;
	  // padding-top: 20rpx;
	  padding: 0rpx 20rpx;
	  flex-direction: row-reverse;
	  // border-top: thin solid #f2f2f2;
	  
	  .btnCheck {
	  
	  		// width: 128upx;
			padding: 0 30rpx;
	  		height: 52upx;
	  		border-radius: 26upx;
	  		border: thin solid #CECECE;
	  		font-size: 22upx;
	  		color: #333;
	  		line-height: 52rpx;
	  		text-align: center;
			font-weight: 400;
			margin-left:20rpx;
	  		// margin-right: 20upx;
	  
	  	}
			
		.btnRed{
			color: #0005C9;
			border: thin solid #2D63F9;
		}
  }
  
</style>
